<!DOCTYPE html>


<html lang="zn-CH">


<head>
  <meta charset="utf-8" />
    
  <meta name="description" content="What I can do is to Do My Personal Best!" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    SpringAOP + 注解实现日志管理 |  小熊的博客
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="http://www.cdn.adingxiong.com/b5363a06dc744d79a94021492bcefe27" />
  
  
<link rel="stylesheet" href="/blog/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/blog/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  

<link rel="alternate" href="/blog/atom.xml" title="小熊的博客" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    <main class="content on">
      <section class="outer">
  <article id="post-SpringAOP-注解实现日志管理" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  SpringAOP + 注解实现日志管理
</h1>
 

    </header>
    

    
    <div class="article-meta">
      <a href="/blog/2020/10/10/SpringAOP-%E6%B3%A8%E8%A7%A3%E5%AE%9E%E7%8E%B0%E6%97%A5%E5%BF%97%E7%AE%A1%E7%90%86/" class="article-date">
  <time datetime="2020-10-10T02:33:04.000Z" itemprop="datePublished">2020-10-10</time>
</a>
      
      
      
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> Word count:</span>
            <span class="post-count">999</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> Reading time≈</span>
            <span class="post-count">4 min</span>
        </span>
    </span>
</div>

      
    </div>
    

    
    
    <div class="tocbot"></div>





    

    
    <div class="article-entry" itemprop="articleBody">
      
      

      
      <section id="nice" data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="font-size: 16px; color: black; padding: 0 10px; line-height: 1.6; word-spacing: 0px; letter-spacing: 0px; word-break: break-word; word-wrap: break-word; text-align: left; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, 'PingFang SC', Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;"><h1 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; font-size: 1.8em; color: #009688; margin: 1.2em auto; text-align: center; border-bottom: 1px solid #009688;"><span class="prefix" style="display: none;"></span><span class="content">SpringAOP + 注解实现日志管理</span><span class="suffix"></span></h1>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 20px; margin: 0.6em auto; padding-left: 10px; border-left: 2px solid #009688;"><span class="prefix" style="display: none;"></span><span class="content">1. 什么是<code>AOP</code>?</span><span class="suffix" style="display: none;"></span></h3>
<p data-tool="mdnice编辑器" style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; text-align: justify;"><code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #009688;">AOP</code>(Aspect Orient Programming),翻译过来就是面向切面编程,面向对象编程是将程序抽象成多个层次的对象,面向切面是将程序抽象成多个切面
<img src="https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/b43d36383aaa48bbabcde48860b18eed~tplv-k3u1fbpfcp-watermark.image" alt style="display: block; margin: 0 auto; max-width: 100%;"></p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 20px; margin: 0.6em auto; padding-left: 10px; border-left: 2px solid #009688;"><span class="prefix" style="display: none;"></span><span class="content">2. 为什么要使用<code>AOP</code>(场景说明)</span><span class="suffix" style="display: none;"></span></h3>
<p data-tool="mdnice编辑器" style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; text-align: justify;">在时间开发中,我们有很多模块中会使用到重复的代码,我们肯定不会通过复制的形式来复用代码.当然解决方式也是多种的,通常我们会将重复的代码抽离出来,提取成一个方法或者是一个抽象的类.然后在需要调用的地方,调用这个方法即可.但是随着我们的业务改变,加入改方法被删除不需要使用,我们需要对所有调用的地方进行单独的删除,这就增加了工作的难度,此时便有了<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #009688;">AOP</code>.<strong style="font-weight: bold; color: black;"><code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #009688;">AOP</code>的原理是代理模式</strong></p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 20px; margin: 0.6em auto; padding-left: 10px; border-left: 2px solid #009688;"><span class="prefix" style="display: none;"></span><span class="content">3. 实际案例</span><span class="suffix" style="display: none;"></span></h3>
<p data-tool="mdnice编辑器" style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; text-align: justify;">使用AOP的方式,完成日志管理</p>
<h4 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; margin: 0.6em auto; font-size: 1.2em; padding-left: 10px; border-left: 2px dashed #009688;"><span class="prefix" style="display: none;"></span><span class="content">1. 日志管理数据结构</span><span class="suffix" style="display: none;"></span></h4>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;"><span style="display: block; background: url(https://my-wechat.mdnice.com/point.png); height: 30px; width: 100%; background-size: 40px; background-repeat: no-repeat; background-color: #1E1E1E; margin-bottom: -7px; border-radius: 5px; background-position: 10px 10px;"></span><code class="hljs" style="overflow-x: auto; padding: 16px; color: #DCDCDC; display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #1E1E1E; border-radius: 5px;"><span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">CREATE</span> <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">TABLE</span> <span class="hljs-string" style="color: #D69D85; line-height: 26px;">`sys_log`</span> (
<span>  <span class="hljs-string" style="color: #D69D85; line-height: 26px;">`id`</span> <span class="hljs-built_in" style="color: #4EC9B0; line-height: 26px;">int</span>(<span class="hljs-number" style="color: #B8D7A3; line-height: 26px;">11</span>) <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">NOT</span> <span class="hljs-literal" style="color: #569CD6; line-height: 26px;">NULL</span> AUTO_INCREMENT,
<span>  <span class="hljs-string" style="color: #D69D85; line-height: 26px;">`operation`</span> <span class="hljs-built_in" style="color: #4EC9B0; line-height: 26px;">varchar</span>(<span class="hljs-number" style="color: #B8D7A3; line-height: 26px;">50</span>) <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">DEFAULT</span> <span class="hljs-literal" style="color: #569CD6; line-height: 26px;">NULL</span> <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">COMMENT</span> <span class="hljs-string" style="color: #D69D85; line-height: 26px;">'操作'</span>,
<span>  <span class="hljs-string" style="color: #D69D85; line-height: 26px;">`create_time`</span> datetime <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">DEFAULT</span> <span class="hljs-literal" style="color: #569CD6; line-height: 26px;">NULL</span> <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">COMMENT</span> <span class="hljs-string" style="color: #D69D85; line-height: 26px;">'创建时间'</span>,
<span>  <span class="hljs-string" style="color: #D69D85; line-height: 26px;">`method_name`</span> <span class="hljs-built_in" style="color: #4EC9B0; line-height: 26px;">varchar</span>(<span class="hljs-number" style="color: #B8D7A3; line-height: 26px;">100</span>) <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">DEFAULT</span> <span class="hljs-literal" style="color: #569CD6; line-height: 26px;">NULL</span> <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">COMMENT</span> <span class="hljs-string" style="color: #D69D85; line-height: 26px;">'方法名'</span>,
<span>  <span class="hljs-string" style="color: #D69D85; line-height: 26px;">`param_name`</span> <span class="hljs-built_in" style="color: #4EC9B0; line-height: 26px;">varchar</span>(<span class="hljs-number" style="color: #B8D7A3; line-height: 26px;">500</span>) <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">DEFAULT</span> <span class="hljs-literal" style="color: #569CD6; line-height: 26px;">NULL</span> <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">COMMENT</span> <span class="hljs-string" style="color: #D69D85; line-height: 26px;">'参数'</span>,
<span>  <span class="hljs-string" style="color: #D69D85; line-height: 26px;">`ip`</span> <span class="hljs-built_in" style="color: #4EC9B0; line-height: 26px;">varchar</span>(<span class="hljs-number" style="color: #B8D7A3; line-height: 26px;">100</span>) <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">DEFAULT</span> <span class="hljs-literal" style="color: #569CD6; line-height: 26px;">NULL</span> <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">COMMENT</span> <span class="hljs-string" style="color: #D69D85; line-height: 26px;">'ip地址'</span>,
<span>  <span class="hljs-string" style="color: #D69D85; line-height: 26px;">`username`</span> <span class="hljs-built_in" style="color: #4EC9B0; line-height: 26px;">varchar</span>(<span class="hljs-number" style="color: #B8D7A3; line-height: 26px;">50</span>) <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">DEFAULT</span> <span class="hljs-literal" style="color: #569CD6; line-height: 26px;">NULL</span> <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">COMMENT</span> <span class="hljs-string" style="color: #D69D85; line-height: 26px;">'用户名'</span>,
<span>  PRIMARY <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">KEY</span> (<span class="hljs-string" style="color: #D69D85; line-height: 26px;">`id`</span>),
<span>  <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">UNIQUE</span> <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">KEY</span> <span class="hljs-string" style="color: #D69D85; line-height: 26px;">`id`</span> (<span class="hljs-string" style="color: #D69D85; line-height: 26px;">`id`</span>)
<span>) <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">ENGINE</span>=<span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">InnoDB</span> AUTO_INCREMENT=<span class="hljs-number" style="color: #B8D7A3; line-height: 26px;">5</span> <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">DEFAULT</span> <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">CHARSET</span>=utf8
<span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
<p data-tool="mdnice编辑器" style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; text-align: justify;">日志表对应的实体类,<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #009688;">mapper</code>,<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #009688;">service</code>,<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #009688;">controller</code> 可以通过<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #009688;">mybatisplus</code>自动生成,这里就省略不写了.</p>
<h4 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; margin: 0.6em auto; font-size: 1.2em; padding-left: 10px; border-left: 2px dashed #009688;"><span class="prefix" style="display: none;"></span><span class="content">2. 日志管理切入面(代码加强)</span><span class="suffix" style="display: none;"></span></h4>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;"><span style="display: block; background: url(https://my-wechat.mdnice.com/point.png); height: 30px; width: 100%; background-size: 40px; background-repeat: no-repeat; background-color: #1E1E1E; margin-bottom: -7px; border-radius: 5px; background-position: 10px 10px;"></span><code class="hljs" style="overflow-x: auto; padding: 16px; color: #DCDCDC; display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #1E1E1E; border-radius: 5px;"><span class="hljs-comment" style="color: #57A64A; font-style: italic; line-height: 26px;">/**
<span> * <span class="hljs-doctag" style="color: #608B4E; line-height: 26px;">@ClassName</span> LoginLogAspect
<span> * <span class="hljs-doctag" style="color: #608B4E; line-height: 26px;">@Description</span>  操作日志切入面
<span> * <span class="hljs-doctag" style="color: #608B4E; line-height: 26px;">@Author</span> xiongchao
<span> * <span class="hljs-doctag" style="color: #608B4E; line-height: 26px;">@Date</span> 2020/9/27 10:22
<span> **/</span>
<span><span class="hljs-meta" style="color: #9B9B9B; line-height: 26px;">@Aspect</span>
<span><span class="hljs-meta" style="color: #9B9B9B; line-height: 26px;">@Component</span>
<span><span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">public</span> <span class="hljs-class" style="color: #B8D7A3; line-height: 26px;"><span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">class</span> <span class="hljs-title" style="color: #DCDCDC; line-height: 26px;">SysLogAspect</span> </span>{
<span>
<span>    <span class="hljs-meta" style="color: #9B9B9B; line-height: 26px;">@Autowired</span>
<span>    <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">private</span> ISysLogService logService;
<span>
<span>    <span class="hljs-meta" style="color: #9B9B9B; line-height: 26px;">@Autowired</span>
<span>    <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">private</span> ApplicationProperties properties;
<span>
<span>    <span class="hljs-meta" style="color: #9B9B9B; line-height: 26px;">@Autowired</span>
<span>    <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">private</span> JwtTokenUtil util;
<span>
<span>    <span class="hljs-comment" style="color: #57A64A; font-style: italic; line-height: 26px;">//定义切点 @Pointcut</span>
<span>    <span class="hljs-comment" style="color: #57A64A; font-style: italic; line-height: 26px;">//在注解的位置切入代码</span>
<span>    <span class="hljs-meta" style="color: #9B9B9B; line-height: 26px;">@Pointcut</span>(<span class="hljs-string" style="color: #D69D85; line-height: 26px;">"@annotation( com.adingxiong.cft.aop.Mylog)"</span>)
<span>    <span class="hljs-function" style="color: #DCDCDC; line-height: 26px;"><span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">public</span> <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">void</span> <span class="hljs-title" style="color: #DCDCDC; line-height: 26px;">logPoinCut</span><span class="hljs-params" style="color: #DCDCDC; line-height: 26px;">()</span> </span>{
<span>
<span>    }
<span>
<span>    <span class="hljs-comment" style="color: #57A64A; font-style: italic; line-height: 26px;">//切面 配置通知</span>
<span>    <span class="hljs-meta" style="color: #9B9B9B; line-height: 26px;">@AfterReturning</span>(<span class="hljs-string" style="color: #D69D85; line-height: 26px;">"logPoinCut()"</span>)
<span>    <span class="hljs-function" style="color: #DCDCDC; line-height: 26px;"><span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">public</span> <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">void</span> <span class="hljs-title" style="color: #DCDCDC; line-height: 26px;">savaLog</span><span class="hljs-params" style="color: #DCDCDC; line-height: 26px;">(JoinPoint joinpoin)</span></span>{
<span>
<span>        SysLog sysLog = <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">new</span> SysLog();
<span>
<span>        <span class="hljs-comment" style="color: #57A64A; font-style: italic; line-height: 26px;">//从切面织入点处通过反射机制获取织入点处的方法</span>
<span>        MethodSignature signature = (MethodSignature) joinpoin.getSignature();
<span>        <span class="hljs-comment" style="color: #57A64A; font-style: italic; line-height: 26px;">//获取切入点所在的方法</span>
<span>        Method method = signature.getMethod();
<span>        Mylog myLog = method.getAnnotation(Mylog.class);
<span>
<span>        <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">if</span>(myLog != <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">null</span>){
<span>            String value  = myLog.value();
<span>            sysLog.setOperation(value);
<span>        }
<span>
<span>        <span class="hljs-comment" style="color: #57A64A; font-style: italic; line-height: 26px;">//获取请求的类名</span>
<span>        String className = joinpoin.getTarget().getClass().getName();
<span>
<span>        <span class="hljs-comment" style="color: #57A64A; font-style: italic; line-height: 26px;">//获取请求的方法名</span>
<span>        String methodName = method.getName();
<span>        sysLog.setMethodName(className + <span class="hljs-string" style="color: #D69D85; line-height: 26px;">"."</span> + methodName);
<span>
<span>        HttpServletRequest request=((ServletRequestAttributes) RequestContextHolder
<span>                .getRequestAttributes()).getRequest();
<span>
<span>        String token  = request.getHeader(properties.getTokenHeader());
<span>
<span>        String authToken = token.substring(properties.getTokenHead().length());
<span>        String username = util.getUserNameFromToken(authToken);
<span>
<span>        sysLog.setUsername(username);
<span>
<span>        String ip = IpUtils.getRealIp(request);
<span>        sysLog.setIp(ip);
<span>
<span>        <span class="hljs-comment" style="color: #57A64A; font-style: italic; line-height: 26px;">//请求参数</span>
<span>        Object args [] = joinpoin.getArgs();
<span>        String param = JSON.toJSONString(args);
<span>        sysLog.setParamName(param);
<span>        sysLog.setCreateTime(<span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">new</span> Date());
<span>        logService.save(sysLog);
<span>    }
<span>
<span>}
<span>
<span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
<h4 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; margin: 0.6em auto; font-size: 1.2em; padding-left: 10px; border-left: 2px dashed #009688;"><span class="prefix" style="display: none;"></span><span class="content">3. 获取<code>IP</code>的工具类</span><span class="suffix" style="display: none;"></span></h4>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;"><span style="display: block; background: url(https://my-wechat.mdnice.com/point.png); height: 30px; width: 100%; background-size: 40px; background-repeat: no-repeat; background-color: #1E1E1E; margin-bottom: -7px; border-radius: 5px; background-position: 10px 10px;"></span><code class="hljs" style="overflow-x: auto; padding: 16px; color: #DCDCDC; display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #1E1E1E; border-radius: 5px;"><span class="hljs-comment" style="color: #57A64A; font-style: italic; line-height: 26px;">/**
<span> * <span class="hljs-doctag" style="color: #608B4E; line-height: 26px;">@ClassName</span> IpUtils
<span> * <span class="hljs-doctag" style="color: #608B4E; line-height: 26px;">@Description</span>  获取用户的真实ip
<span> * <span class="hljs-doctag" style="color: #608B4E; line-height: 26px;">@Author</span> xiongchao
<span> * <span class="hljs-doctag" style="color: #608B4E; line-height: 26px;">@Date</span> 2020/9/27 10:08
<span> **/</span>
<span><span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">public</span> <span class="hljs-class" style="color: #B8D7A3; line-height: 26px;"><span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">class</span> <span class="hljs-title" style="color: #DCDCDC; line-height: 26px;">IpUtils</span> </span>{
<span>
<span>    <span class="hljs-function" style="color: #DCDCDC; line-height: 26px;"><span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">public</span> <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">static</span> String <span class="hljs-title" style="color: #DCDCDC; line-height: 26px;">getRealIp</span><span class="hljs-params" style="color: #DCDCDC; line-height: 26px;">(HttpServletRequest request)</span> </span>{
<span>        String ipAddress = request.getHeader(<span class="hljs-string" style="color: #D69D85; line-height: 26px;">"x-forwarded-for"</span>);
<span>        <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">if</span>(ipAddress == <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">null</span> || ipAddress.length() ==<span class="hljs-number" style="color: #B8D7A3; line-height: 26px;">0</span> || <span class="hljs-string" style="color: #D69D85; line-height: 26px;">"unknown"</span>.equals(ipAddress)){
<span>            ipAddress = request.getHeader(<span class="hljs-string" style="color: #D69D85; line-height: 26px;">"Proxy-Client-IP"</span>);
<span>        }
<span>        <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">if</span>(ipAddress == <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">null</span> || ipAddress.length() == <span class="hljs-number" style="color: #B8D7A3; line-height: 26px;">0</span> || <span class="hljs-string" style="color: #D69D85; line-height: 26px;">"unknown"</span>.equalsIgnoreCase(ipAddress)) {
<span>            ipAddress = request.getHeader(<span class="hljs-string" style="color: #D69D85; line-height: 26px;">"WL-Proxy-Client-IP"</span>);
<span>        }
<span>        <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">if</span> (StringUtils.isEmpty(ipAddress) || <span class="hljs-string" style="color: #D69D85; line-height: 26px;">"unknown"</span>.equalsIgnoreCase(ipAddress)) {
<span>            ipAddress = request.getHeader(<span class="hljs-string" style="color: #D69D85; line-height: 26px;">"HTTP_CLIENT_IP"</span>);
<span>        }
<span>        <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">if</span> (StringUtils.isEmpty(ipAddress) || <span class="hljs-string" style="color: #D69D85; line-height: 26px;">"unknown"</span>.equalsIgnoreCase(ipAddress)) {
<span>            ipAddress = request.getHeader(<span class="hljs-string" style="color: #D69D85; line-height: 26px;">"HTTP_X_FORWARDED_FOR"</span>);
<span>        }
<span>        <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">if</span>(ipAddress == <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">null</span> || ipAddress.length() == <span class="hljs-number" style="color: #B8D7A3; line-height: 26px;">0</span> || <span class="hljs-string" style="color: #D69D85; line-height: 26px;">"unknown"</span>.equalsIgnoreCase(ipAddress)) {
<span>            ipAddress = request.getRemoteAddr();
<span>            <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">if</span>(ipAddress.equals(<span class="hljs-string" style="color: #D69D85; line-height: 26px;">"127.0.0.1"</span>) || ipAddress.equals(<span class="hljs-string" style="color: #D69D85; line-height: 26px;">"0:0:0:0:0:0:0:1"</span>)){
<span>                <span class="hljs-comment" style="color: #57A64A; font-style: italic; line-height: 26px;">//根据网卡取本机配置的IP</span>
<span>                InetAddress inet=<span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">null</span>;
<span>                <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">try</span> {
<span>                    inet = InetAddress.getLocalHost();
<span>                } <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">catch</span> (UnknownHostException e) {
<span>                    e.printStackTrace();
<span>                }
<span>                ipAddress= inet.getHostAddress();
<span>            }
<span>        }
<span>        <span class="hljs-comment" style="color: #57A64A; font-style: italic; line-height: 26px;">//对于通过多个代理的情况，第一个IP为客户端真实IP,多个IP按照','分割</span>
<span>        <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">if</span>(ipAddress!=<span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">null</span> &amp;&amp; ipAddress.length()&gt;<span class="hljs-number" style="color: #B8D7A3; line-height: 26px;">15</span>){ <span class="hljs-comment" style="color: #57A64A; font-style: italic; line-height: 26px;">//"***.***.***.***".length() = 15</span>
<span>            <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">if</span>(ipAddress.indexOf(<span class="hljs-string" style="color: #D69D85; line-height: 26px;">","</span>)&gt;<span class="hljs-number" style="color: #B8D7A3; line-height: 26px;">0</span>){
<span>                ipAddress = ipAddress.substring(<span class="hljs-number" style="color: #B8D7A3; line-height: 26px;">0</span>,ipAddress.indexOf(<span class="hljs-string" style="color: #D69D85; line-height: 26px;">","</span>));
<span>            }
<span>        }
<span>        <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">return</span> ipAddress;
<span>    }
<span>
<span>}
<span>
<span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
<h4 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; margin: 0.6em auto; font-size: 1.2em; padding-left: 10px; border-left: 2px dashed #009688;"><span class="prefix" style="display: none;"></span><span class="content">4. 自定义注解(通过注解的方式调用切面方法)</span><span class="suffix" style="display: none;"></span></h4>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;"><span style="display: block; background: url(https://my-wechat.mdnice.com/point.png); height: 30px; width: 100%; background-size: 40px; background-repeat: no-repeat; background-color: #1E1E1E; margin-bottom: -7px; border-radius: 5px; background-position: 10px 10px;"></span><code class="hljs" style="overflow-x: auto; padding: 16px; color: #DCDCDC; display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #1E1E1E; border-radius: 5px;"><span class="hljs-comment" style="color: #57A64A; font-style: italic; line-height: 26px;">/**
<span> * <span class="hljs-doctag" style="color: #608B4E; line-height: 26px;">@ClassName</span> Mylog
<span> * <span class="hljs-doctag" style="color: #608B4E; line-height: 26px;">@Description</span> TODO
<span> * <span class="hljs-doctag" style="color: #608B4E; line-height: 26px;">@Author</span> xiongchao
<span> * <span class="hljs-doctag" style="color: #608B4E; line-height: 26px;">@Date</span> 2020/9/27 10:29
<span> **/</span>
<span><span class="hljs-meta" style="color: #9B9B9B; line-height: 26px;">@Target</span>(ElementType.METHOD) <span class="hljs-comment" style="color: #57A64A; font-style: italic; line-height: 26px;">//注解放置的目标位置,METHOD是可注解在方法级别上</span>
<span><span class="hljs-meta" style="color: #9B9B9B; line-height: 26px;">@Retention</span>(RetentionPolicy.RUNTIME) <span class="hljs-comment" style="color: #57A64A; font-style: italic; line-height: 26px;">//注解在哪个阶段执行</span>
<span><span class="hljs-meta" style="color: #9B9B9B; line-height: 26px;">@Documented</span> <span class="hljs-comment" style="color: #57A64A; font-style: italic; line-height: 26px;">//生成文档</span>
<span><span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">public</span> <span class="hljs-meta" style="color: #9B9B9B; line-height: 26px;">@interface</span> Mylog {
<span>    <span class="hljs-function" style="color: #DCDCDC; line-height: 26px;">String <span class="hljs-title" style="color: #DCDCDC; line-height: 26px;">value</span><span class="hljs-params" style="color: #DCDCDC; line-height: 26px;">()</span> <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">default</span> ""</span>;
<span>}
<span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
<h4 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; margin: 0.6em auto; font-size: 1.2em; padding-left: 10px; border-left: 2px dashed #009688;"><span class="prefix" style="display: none;"></span><span class="content">5. 测试</span><span class="suffix" style="display: none;"></span></h4>
<p data-tool="mdnice编辑器" style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; text-align: justify;">在<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #009688;">Service</code>层或者<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #009688;">controller</code>层添加<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #009688;">@MyLog(value="xxxxx")</code>注解完成调用</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;"><span style="display: block; background: url(https://my-wechat.mdnice.com/point.png); height: 30px; width: 100%; background-size: 40px; background-repeat: no-repeat; background-color: #1E1E1E; margin-bottom: -7px; border-radius: 5px; background-position: 10px 10px;"></span><code class="hljs" style="overflow-x: auto; padding: 16px; color: #DCDCDC; display: block; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #1E1E1E; border-radius: 5px;">    <span class="hljs-meta" style="color: #9B9B9B; line-height: 26px;">@Mylog</span>(value = <span class="hljs-string" style="color: #D69D85; line-height: 26px;">"获取当前用户信息"</span>)
<span>    <span class="hljs-meta" style="color: #9B9B9B; line-height: 26px;">@ApiOperation</span>(value = <span class="hljs-string" style="color: #D69D85; line-height: 26px;">"获取当前登录用户信息"</span>)
<span>    <span class="hljs-meta" style="color: #9B9B9B; line-height: 26px;">@GetMapping</span>(<span class="hljs-string" style="color: #D69D85; line-height: 26px;">"/info"</span>)
<span>    <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">public</span> Result&lt;Map&lt;String,Object&gt;&gt; getUserInfo(Principal principal){
<span>        <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">if</span>(principal == <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">null</span>){
<span>            <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">return</span> Result.unauthorized(<span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">null</span>);
<span>        }
<span>        String username = principal.getName();
<span>        TUser user = userService.getUserByUsername(username);
<span>        List&lt;Role&gt; list = roleService.getUserRole(user.getId());
<span>        Map&lt;String,Object&gt; res = <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">new</span> HashMap&lt;&gt;();
<span>        res.put(<span class="hljs-string" style="color: #D69D85; line-height: 26px;">"userInfo"</span>,user);
<span>        res.put(<span class="hljs-string" style="color: #D69D85; line-height: 26px;">"role"</span>,list);
<span>        <span class="hljs-keyword" style="color: #569CD6; line-height: 26px;">return</span> Result.success(res);
<span>    }
<span>
<span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
<figure data-tool="mdnice编辑器" style="margin: 0; margin-top: 10px; margin-bottom: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center;"><img src="https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/82823cb8be59494aa135911dae43209f~tplv-k3u1fbpfcp-watermark.image" alt style="display: block; margin: 0 auto; max-width: 100%;"></figure>
<p id="nice-suffix-juejin-container" class="nice-suffix-juejin-container" data-tool="mdnice编辑器" style="font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0; line-height: 26px; color: black; text-align: justify; margin-top: 20px !important;">本文使用 <a href="https://mdnice.com/?from=juejin" target="_blank" rel="noopener" style="text-decoration: none; word-wrap: break-word; font-weight: bold; color: #009688; border-bottom: 1px solid #009688;">mdnice</a> 排版</p></section>
      
      <!-- reward -->
      
      <div id="reward-btn">
        Donate
      </div>
      
    </div>
    
    
      <!-- copyright -->
      
        <div class="declare">
          <ul class="post-copyright">
            <li>
              <i class="ri-copyright-line"></i>
              <strong>Copyright： </strong>
              Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
            </li>
          </ul>
        </div>
        
    <footer class="article-footer">
      
          
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://bodboy.gitee.io/blog/2020/10/10/SpringAOP-%E6%B3%A8%E8%A7%A3%E5%AE%9E%E7%8E%B0%E6%97%A5%E5%BF%97%E7%AE%A1%E7%90%86/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/AOP/" rel="tag">AOP</a></li></ul>


    </footer>

  </div>

  
  
  <nav class="article-nav">
    
      <a href="/blog/2020/10/13/zookeeper%E9%83%A8%E7%BD%B2%E5%AE%89%E8%A3%85/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            zookeeper部署安装
          
        </div>
      </a>
    
    
      <a href="/blog/2020/10/09/Quill%E7%BC%96%E8%BE%91%E5%99%A8%E8%87%AA%E5%AE%9A%E4%B9%89%E5%AD%97%E4%BD%93%E5%92%8C%E5%AD%97%E4%BD%93%E5%A4%A7%E5%B0%8F/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">Quill编辑器自定义字体和字体大小</div>
      </a>
    
  </nav>


  

  
  
<!-- valine评论 -->
<div id="vcomments-box">
    <div id="vcomments">
    </div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'></script>
<script>
    new Valine({
        el: '#vcomments',
        app_id: 'uW8QYGvvhWmNWdiwpznJ0GVa-gzGzoHsz',
        app_key: 'LrJhMzx9qEwcMV1DJjTI6f6C',
        path: window.location.pathname,
        notify: 'false',
        verify: 'false',
        avatar: '[object Object]',
        placeholder: '给我的文章加点评论吧~',
        recordIP: true
    });
    const infoEle = document.querySelector('#vcomments .info');
    if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
        infoEle.childNodes.forEach(function (item) {
            item.parentNode.removeChild(item);
        });
    }
</script>
<style>
    #vcomments-box {
        padding: 5px 30px;
    }

    @media screen and (max-width: 800px) {
        #vcomments-box {
            padding: 5px 0px;
        }
    }

    #vcomments-box #vcomments {
        background-color: #fff;
    }

    .v .vlist .vcard .vh {
        padding-right: 20px;
    }

    .v .vlist .vcard {
        padding-left: 10px;
    }
</style>

  

  
  
  
  
  

</article>
</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2019-2021
        <i class="ri-heart-fill heart_icon"></i> panda
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        Powered by <a href="https://hexo.io" target="_blank">Hexo</a>
        <span class="division">|</span>
        Theme - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>Visitors:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>Views:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/blog/"><img src="https://portrait.gitee.com/uploads/avatars/user/1007/3023420_bodboy_1578973210.png!avatar200" alt="小熊的博客"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/tags/%E6%97%85%E8%A1%8C/">旅行</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/blog/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/blog/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/blog/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/blog/js/jquery-2.0.3.min.js"></script>


<script src="/blog/js/lazyload.min.js"></script>


<script>
  try {
    var typed = new Typed("#subtitle", {
      strings: ['面朝大海，春暖花开', '愿你一生努力，一生被爱', '想要的都拥有，得不到的都释怀'],
      startDelay: 0,
      typeSpeed: 200,
      loop: true,
      backSpeed: 100,
      showCursor: true
    });
  } catch (err) {
  }

</script>




<script src="/blog/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>



<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/blog/dist/main.js"></script>



<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>


<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
  var ayerConfig = {
    mathjax: true
  }
</script>




<script src="/blog/js/busuanzi-2.3.pure.min.js"></script>



<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>

  
<script src="/blog/js/clickLove.js"></script>



<!-- 复制 -->



    
    <div id="music">
    
    
    
    <iframe frameborder="no" border="1" marginwidth="0" marginheight="0" width="200" height="52"
        src="//music.163.com/outchain/player?type=2&id=1297802566&auto=1&height=32"></iframe>
</div>

<style>
    #music {
        position: fixed;
        right: 15px;
        bottom: 0;
        z-index: 998;
    }
</style>
    
  </div>
</body>

</html>